<template>
  <div class="wrapper">
    <swiper :options="swiperOption">
      <!-- slides -->
      <swiper-slide v-for="item of swiperList" :key="item.id">
        <img class="swiperImg" :src="item.imgUrl" alt="" />
      </swiper-slide>
      <!-- Optional controls以下按需使用 -->
      <div class="swiper-pagination" slot="pagination"></div>
      <!--分页-->
    </swiper>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "HomeSwiper",
  data() {
    return {
      swiperOption: {
        pagination: ".swiper-pagination",
        loop: true,
      },
      swiperList: [],
    };
  },

  methods: {
    loadData() {
      axios
        .get("http://localhost:3000/swiperList")
        .then((res) => {
          this.swiperList = res.data;
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  mounted() {
    this.loadData();
  },
};
</script>

<style lang='stylus' scoped>
.swiperImg {
  width: 100%;
}

.wrapper {
  padding-bottom: 31%;
  width: 100%;
  height: 0;
  overflow: hidden;
  background: #eee;
  margin-bottom: 0.1rem;
}

.wrapper >>>.swiper-pagination-bullet-active {
  background: #fff;
}
</style>